package LearnDataStructure.d_图结构;

import java.util.ArrayList;
import java.util.List;

/**
 * @version: 1.0
 * @Author: wuqiu
 * @date: 2023-07-14 12:45
 * @description: LeetcodeLearnAlgorithm -> LearnDataStructure.d_图结构
 */
public class GraphNode_AdjacencyList {
    public int value = 0;//当前节点在图中的数值
    private List<GraphNode_AdjacencyList> neighbors = null;//所有邻居节点
    public boolean checked = false;
    public int color = 0;//同时标记了“已访问”和“颜色”

    public GraphNode_AdjacencyList(int value) {
        this.value = value;
    }

    public GraphNode_AdjacencyList(int value, int color) {
        this.value = value;
        this.color = color;
    }

    public List<GraphNode_AdjacencyList> getNeighbors() {
        return neighbors;
    }

    /**
     * 添加邻居节点
     * @param node
     */
    public void add(GraphNode_AdjacencyList node) {
        if (this.neighbors == null) {
            this.neighbors = new ArrayList<GraphNode_AdjacencyList>();
        }
        neighbors.add(node);
    }

    public int getSize() {
        if (neighbors != null) {
            return neighbors.size();
        } else {
            return -1;
        }
    }

    @Override
    public String toString() {
        return "GraphNode_AdjacencyList{" +
                "value=" + value +
                ", neighbors=" + neighbors +
                ", checked=" + checked +
                ", color=" + color +
                '}';
    }
}
